/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.util;

/**
 *
 * @author GiangLT
 */
public class CommonUtil {

    public static char nativeToSimplified(char vnNativeChar) {
        if (Constant.vnNativeChars.contains(vnNativeChar)) {
            int idx = Constant.vnNativeChars.indexOf(vnNativeChar);
            return Constant.vnSimplyfiedChars.get(idx);
        }
        return vnNativeChar;
    }

    public static String nativeToSimplified(String nativeString) {
        char[] chars = nativeString.toCharArray();
        char[] result = new char[chars.length];
        int idx = 0;
        for (char character : chars) {
            result[idx] = CommonUtil.nativeToSimplified(character);
            idx++;
        }
        return new String(result);
    }

    public static String normalizeMsisdn(String rawMsisdn) {
        String result;
        if (rawMsisdn.startsWith("0")) {
            result = rawMsisdn.replaceFirst("0", "84");
        } else if (rawMsisdn.startsWith("+84")) {
            result = rawMsisdn.replace("+", "");
        } else if (rawMsisdn.startsWith("84")) {
            result = rawMsisdn;
        } else {
            result = "84" + rawMsisdn;
        }
        return result;
    }

    public static String getPrefix(String msisdn) {
        if (msisdn.length() == 11) {
            return msisdn.substring(0, 4);
        } else if (msisdn.length() == 12) {
            return msisdn.substring(0, 5);
        }
        return null;

    }

    public static void main(String[] args) {
        System.out.println(CommonUtil.nativeToSimplified("Trung tâm Nghiên cứu Chiến lược và Quốc tế"));
    }
}
